unit untSellect;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TfrmSellect = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormPaint(Sender: TObject);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure FormClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
    MX, MY, MM, SI: Integer;
    Buffer: TBitMap;
  public
    { Public declarations }
  end;

var
  frmSellect: TfrmSellect;

implementation

uses untMain, untImage, uEditItem, uEditCreature;

{$R *.dfm}

procedure TfrmSellect.FormCreate(Sender: TObject);
begin
  Buffer  := TBitMap.Create;
end;

procedure TfrmSellect.FormDestroy(Sender: TObject);
begin
  Buffer.Free;
end;

procedure TfrmSellect.FormPaint(Sender: TObject);
begin
  Canvas.Draw(0, 0, Buffer);
end;

procedure TfrmSellect.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  if (X >= 0) and (X <= (Buffer.Width)) then MX := X div 32;
  if (Y >= 0) and (Y <= Buffer.Height) then MY := Y div 32;
  MM := (MY * (Buffer.Width div 32)) + MX;
end;

procedure TfrmSellect.FormClick(Sender: TObject);
begin
  if (MM < 0) or (MM > 255) then Exit;
  case frmMain.PC.ActivePageIndex of
    0: begin
         case fEditItem.SlotBox.ItemIndex of
           0, 2, 11, 12: MM := MM + 256;
         end;
         fEditItem.ImageIndex := MM;
         frmMain.ItemsBitmaps[MM].Transparent := False;
         fEditItem.Image1.Canvas.Draw(0, 0, frmMain.ItemsBitmaps[MM]);
         frmImage.Image1.Canvas.Draw(0, 0, frmMain.ItemsBitmaps[MM]);
       end;
    1: begin
         fEditCreature.ImageIndex := MM;
         frmMain.CreaturesBitmaps[MM].Transparent := False;
         fEditCreature.Image1.Canvas.Draw(0, 0, frmMain.CreaturesBitmaps[MM]);
         frmImage.Image1.Canvas.Draw(0, 0, frmMain.CreaturesBitmaps[MM]);
       end;
  end;
  ModalResult := mrOK;
end;

procedure TfrmSellect.FormShow(Sender: TObject);
begin
  SI := frmMain.PC.ActivePageIndex;
  case SI of
    0: case fEditItem.SlotBox.ItemIndex of
         1, 3..7, 8..10: Buffer.LoadFromFile('data\images\ditems1.bmp');
         else Buffer.LoadFromFile('data\images\ditems2.bmp');
       end;
    1: Buffer.LoadFromFile('data\images\creatures.bmp');
  end;
  ClientWidth  := Buffer.Width;
  ClientHeight := Buffer.Height;
end;

end.
